/*
* 标签库
* date 2013-1-9
*/
var tagDialog={
	setting:{
		ajaxUrl:'',
		preBtnId:'dialog_tag_pre',
		nextBtnId:'dialog_tag_next',
		contentId:'dialog_tag_content_value',
		transferId:'tagsHandle',
		currentPage:1
	},
	init:function(param){
		var that=this;
		that.setting=$.extend({},that.setting,param); 	
		that.addTemplateToDialog(that.template);
		that.initData();
		that.bindEvent();
	},
	addTemplateToDialog:function(html){
		dialog.init({'title':'标签库','html':html});
		dialog.position();
	},
	bindEvent:function(){
		var that=this;
		var $preBtn=$('#'+that.setting.preBtnId);
		var $nextBtn=$('#'+that.setting.nextBtnId);
		$preBtn.on('click',function(){
			that.setting.currentPage--;
		});
		$nextBtn.on('click',function(){
			that.setting.currentPage++;
		});	
		$('#'+that.setting.contentId).delegate("a", "click", function(){	
			var $this=$(this);
			var txt=$this.html();
			that.addTagToTransfer(txt);
		});
	},
	initData:function(){
		var that=this;
		var $content=$('#'+that.setting.contentId);
		var links=[];
		for(var i=0;i<50;i++)
		{
			links.push('<a href="javascript:void(0);" title="PHP">PHP'+i+'</a>');
		}
		$content.html(links.join(''));
	},
	addTagToTransfer:function(txt){
		var that=this,
		$transfer=$('#'+that.setting.transferId),
		currentTags=$transfer.val();
		if(currentTags=='')
		{
			currentTags=txt;
		}else{
					if(currentTags.indexOf(txt)==-1)
					{
						currentTags+=','+txt;
					}
				}
		$transfer.val(currentTags);		
	},
	template:'<div class="dialog_tag">'
            	 +'<div class="dialog_tag_content clearfix" id="dialog_tag_content_value">'
                 +' </div>'
                 +'<div class="clearfix">'
                	+'<input type="button" value="下一页" class="public_button fr"  id="dialog_tag_next"/>'
                    +'<input type="button" value="上一页" class="public_button fr mr10"  id="dialog_tag_pre"/>'
                +'</div>'
           +' </div>'
};